<template>
	<view class="content">
		<view class="font">
			<view class="firstFont">
				校区：{{schoolArea}}
			</view>
			<view class="secondFont">
				校区是展示书本数据的依据，请确保它被正确选择!
			</view>
			<u-picker :show="show1" :columns="columns" :defaultIndex='[location]' @confirm="getArea()" @cancel="show1=false">
			</u-picker>
			<button class="button" type="default" plain @click="show1=true">{{buttonFont}}</button>
			
		</view>
	
	</view>
</template>

<script>
	export default {
		data() {
			return {
				schoolArea: "",
				buttonFont: "修改校区",
				columns: [
					['海珠校区', '白云校区']
				],
				popShow: false,
				input: '',
				show1:false,
				location:0
			}
		},
		onLoad() {
			console.log('onLoad^^^^^^')
			let vm = this
			vm.bindArea();
		},
		onShow(){
			
		},
		methods: {
			async bindArea(){
				let vm = this
				let header = new Object
				header.Authority = getApp().globalData.Authority
				let nowLocation = await getApp().UniRequest("/twohandbook/user/authority/nowLocation","GET","",header)
				console.log('nowLocation',nowLocation)
				if(nowLocation.code==20000){
					if(nowLocation.data.location==0){
						vm.schoolArea = '海珠校区'
					}else if(nowLocation.data.location==1){
						vm.schoolArea = '白云校区'
					}else{
						vm.schoolArea = '出bug了'
					}
					
					
				}
				// console.log( 'bingArea里面的getApp().globalData.location',getApp().globalData.location)
				// vm.location = getApp().globalData.location
				// if(getApp().globalData.location==0){
				// 	vm.schoolArea = '海珠校区'
				// }else if(getApp().globalData.location==1){
				// 	vm.schoolArea = '白云校区'
				// }
				// else{
				// 	vm.schoolArea = '出bug了'
				// }
			},
			openPop() {
				let vm = this
				vm.popShow = true
			},
			closePop() {
				let vm = this
				vm.popShow = false
			},
		async getArea(a){
				console.log('@@@@@',a)
				uni.showLoading({
					title: '修改中'
				})
				let header = new Object
				header.Authority = getApp().globalData.Authority
				console.log( getApp().globalData.location);
				getApp().globalData.location = this.location = a.indexs[0]
				let toBindLocation = await getApp().UniRequest("/twohandbook/user/authority/toBindLocation?location="+this.location,"GET","",header)
				console.log('绑定校区里面的toBindLocation',toBindLocation)
				// this.ChooseAearShow = false
				if(toBindLocation.code==20000){
					setTimeout(()=>{
						if(a.indexs[0]==0){
							this.schoolArea = '海珠校区'
						}
						else if(a.indexs[0]==1){
							this.schoolArea = '白云校区'
						}else{
							return
						}
						wx.showToast({
						  title: '修改成功',
						  icon: 'success',
						  duration: 1000
						})
						this.show1 = false
					},300)
					
				}
				
				
			},
		

		}
	}
</script>

<style lang="scss">
	.content {
		.font {
			position: relative;
			top: 305rpx;

			.firstFont {
				text-align: center;
				font-size: 40rpx;
				margin-bottom: 25rpx;
			}

			.secondFont {
				margin: auto;
				width: 93%;
				text-align: center;
				font-size: 27rpx;
				font-weight: 300;
			}

			.button {
				width: 42%;
				position: relative;
				top: 590rpx;
				color: #2e9867;
			}
		}
	}
</style>
